<include file="Common/header" />
<title>新建网站角色</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="{$info['role_name']}" placeholder="" id="user-name" name="user-name" datatype="*4-16" nullmsg="用户账户不能为空">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">备注：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="{$info['remark']}" id="remark" name="remark" />
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">角色权限：</label>
			<div class="formControls col-10">
				<dl class="permission-list">
					<dt>
						<label>
							<input type="checkbox" value="" name="user-Character-0" id="user-Character-0"> 全选/反选
						</label>
					</dt>
					<dd>
						<?php foreach($menulist as $ls){ ?>
						<dl class="cl permission-list2">
							<dt>
								<label class="">
									<input type="checkbox" value="{$ls['menu_id']}" name="roleMenu" id="roleMenu" <?php echo strstr(','.$info['role_list'].',', ','.$ls['menu_id'].',') ? 'checked' : ''; ?>> {$ls['menu_name']}
								</label>
							</dt>
							<dd>
								<?php foreach($ls['list'] as $lls){ ?>
								<label class="">
									<input type="checkbox" value="{$lls['menu_id']}" name="roleMenu" id="roleMenu" <?php echo strstr(','.$info['role_list'].',', ','.$lls['menu_id'].',') ? 'checked' : ''; ?>> {$lls['menu_name']}
								</label>
								<?php } ?>
							</dd>
						</dl>
						<?php } ?>
					</dd>
				</dl>
			</div>
		</div>
		<input type="hidden" id="role_id" name="role_id" value="{$info['role_id']}" />
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button type="button" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</div>
<script>
	$(function(){
		$(".permission-list dt input:checkbox").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
		});
		
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
				}
			}
		});
		
		//提交
		$(".radius").on('click', function(){
			var data = {};
				data.role_id = $("#role_id").val();
			var role_name = $("#user-name").val();
			if(role_name.length == 0 || role_name.length > 30){
				layer.msg('角色名称输入格式错误。', {icon: 5, time: 2000});
				return false;
			}else{
				data.role_name = role_name;
			}
			
			var remark = $("#remark").val();
			if(remark.length <= 0 || remark.length > 100){
				layer.msg('角色备注输入格式错误。', {icon: 5, time: 2000});
				return false;
			}else{
				data.remark = remark;
			}
			
			var role_list_list = '';
			$('input[name="roleMenu"]:checked').each(function(){
				if(role_list_list.length <= 0){
					role_list_list = $(this).val() +'';
				}else{
					role_list_list += ','+ $(this).val();
				}
			});
			
			if(role_list_list.length <= 0){
				layer.msg('请选择管理权限', {icon: 5, time: 2000});
				return false;
			}else{
				data.role_list = role_list_list;
			}
			
			$.post('add.html', data, function(row){
				if(row/1){
					layer.msg('操作成功', {icon: 1, time: 2000}, function(){
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
					});
				}else{
					layer.msg('操作失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>